<template>
  <div class="team-detail-page">
    <!-- 团队基本信息 -->
    <div class="team-header">
      <div class="header-content">
        <div class="team-avatar">
          <el-image :src="team.avatar" fit="cover">
            <template #placeholder>
              <div class="image-placeholder">
                <el-icon><Picture /></el-icon>
              </div>
            </template>
          </el-image>
        </div>
        <div class="team-info">
          <div class="team-title">
            <h1>{{ team.name }}</h1>
            <div class="team-badges">
              <el-tag v-if="team.isRecruiting" type="success" effect="dark">
                招募中
              </el-tag>
              <el-tag v-if="team.isVerified" type="primary" effect="dark">
                官方认证
              </el-tag>
            </div>
          </div>
          <p class="team-desc">{{ team.description }}</p>
          <div class="team-meta">
            <div class="meta-item">
              <el-icon><Location /></el-icon>
              <span>{{ team.location }}</span>
            </div>
            <div class="meta-item">
              <el-icon><Calendar /></el-icon>
              <span>成立于 {{ formatDate(team.established) }}</span>
            </div>
          </div>
          <div class="team-tags">
            <el-tag 
              v-for="tag in team.tags" 
              :key="tag"
              :type="getTagType(tag)"
              effect="plain"
            >
              {{ tag }}
            </el-tag>
          </div>
        </div>
        <div class="team-actions">
          <el-button 
            type="primary" 
            size="large"
            :disabled="team.isJoined"
            @click="handleJoinTeam"
          >
            {{ team.isJoined ? '已加入团队' : '加入团队' }}
          </el-button>
          <el-button type="info" plain size="large">
            分享团队
          </el-button>
        </div>
      </div>
    </div>

    <!-- 团队数据统计 -->
    <div class="team-stats-section">
      <div class="stats-container">
        <div class="stat-card">
          <div class="stat-value">{{ team.memberCount }}</div>
          <div class="stat-label">团队成员</div>
        </div>
        <div class="stat-card">
          <div class="stat-value">{{ team.activityCount }}</div>
          <div class="stat-label">活动次数</div>
        </div>
        <div class="stat-card">
          <div class="stat-value">{{ team.serviceHours }}</div>
          <div class="stat-label">服务时长</div>
        </div>
        <div class="stat-card">
          <div class="stat-value">{{ team.rating || 4.8 }}</div>
          <div class="stat-label">团队评分</div>
        </div>
      </div>
    </div>

    <!-- 主要内容区 -->
    <div class="main-content">
      <el-tabs v-model="activeTab" class="team-tabs">
        <!-- 团队介绍 -->
        <el-tab-pane label="团队介绍" name="intro">
          <div class="team-intro">
            <h2>关于我们</h2>
            <p>{{ team.fullDescription || team.description }}</p>
            
            <h2>团队目标</h2>
            <ul class="team-goals">
              <li>保护海洋生态环境，维护海洋生物多样性</li>
              <li>开展海洋环境监测和科研活动</li>
              <li>推广海洋环保理念，提高公众环保意识</li>
              <li>培养专业的海洋保护志愿者队伍</li>
            </ul>

            <h2>加入条件</h2>
            <ul class="join-requirements">
              <li>年满18周岁，身体健康</li>
              <li>具有强烈的环保意识和责任感</li>
              <li>能够参与定期的团队活动和培训</li>
              <li>具备相关专业背景或志愿服务经验者优先</li>
            </ul>
          </div>
        </el-tab-pane>

        <!-- 团队成员 -->
        <el-tab-pane label="团队成员" name="members">
          <div class="members-grid">
            <div v-for="member in teamMembers" :key="member.id" class="member-card">
              <el-avatar :size="80" :src="member.avatar" />
              <h3>{{ member.name }}</h3>
              <p class="member-role">{{ member.role }}</p>
              <p class="member-stats">
                参与活动: {{ member.activityCount }} 次
              </p>
            </div>
          </div>
        </el-tab-pane>

        <!-- 近期活动 -->
        <el-tab-pane label="近期活动" name="activities">
          <div class="activities-list">
            <div v-for="activity in teamActivities" :key="activity.id" class="activity-item">
              <el-image :src="activity.image" fit="cover" class="activity-image" />
              <div class="activity-content">
                <h3>{{ activity.title }}</h3>
                <p>{{ activity.description }}</p>
                <div class="activity-meta">
                  <span>
                    <el-icon><Calendar /></el-icon>
                    {{ formatDate(activity.date) }}
                  </span>
                  <span>
                    <el-icon><Location /></el-icon>
                    {{ activity.location }}
                  </span>
                  <span>
                    <el-icon><User /></el-icon>
                    {{ activity.participants }}人参与
                  </span>
                </div>
                <el-button type="primary" plain size="small">
                  查看详情
                </el-button>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { 
  Picture, Location, Calendar, User 
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const route = useRoute()
const activeTab = ref('intro')

// 模拟团队数据
const team = ref({
  id: 1,
  name: '蔚蓝守护者',
  description: '专注于海洋生态保护的专业志愿者团队，致力于海洋环境保护和科研工作。',
  fullDescription: `我们是一支专业的海洋生态保护志愿者团队，成立于2023年6月。团队由海洋生物学家、环保工作者和热心志愿者组成，致力于海洋环境保护和科研工作。

我们的主要工作包括海洋生态监测、海滩清洁、海洋生物救助、环保教育等。团队定期开展专业培训，提高志愿者的专业素养和服务能力。

加入我们，你将有机会：
1. 参与专业的海洋生态保护工作
2. 获得海洋生态保护相关培训
3. 结识志同道合的伙伴
4. 为海洋生态保护贡献一份力量`,
  avatar: 'https://images.unsplash.com/photo-1621451537084-482c73073a0f?w=800',
  location: '深圳',
  established: '2023-06-15',
  memberCount: 156,
  activityCount: 48,
  serviceHours: 2160,
  rating: 4.8,
  isRecruiting: true,
  isVerified: true,
  isJoined: false,
  tags: ['海洋保护', '科研调查', '环境教育']
})

// 模拟成员数据
const teamMembers = ref([
  {
    id: 1,
    name: '张海洋',
    role: '团队负责人',
    avatar: 'https://images.unsplash.com/photo-1633332755192-727a05c4013d?w=100',
    activityCount: 48
  },
  {
    id: 2,
    name: '李珊珊',
    role: '科研主管',
    avatar: 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=100',
    activityCount: 42
  },
  {
    id: 3,
    name: '王浪',
    role: '活动策划',
    avatar: 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=100',
    activityCount: 36
  }
])

// 模拟活动数据
const teamActivities = ref([
  {
    id: 1,
    title: '深圳湾红树林生态调查',
    description: '开展红树林生态系统调查，记录物种多样性数据。',
    image: 'https://images.unsplash.com/photo-1621451537084-482c73073a0f?w=800',
    date: '2024-04-20',
    location: '深圳湾红树林保护区',
    participants: 25
  },
  {
    id: 2,
    title: '海洋生物多样性监测',
    description: '进行海洋生物多样性调查，收集海洋生态数据。',
    image: 'https://images.unsplash.com/photo-1682687220742-aba13b6e50ba?w=800',
    date: '2024-04-25',
    location: '大鹏新区海洋保护区',
    participants: 18
  }
])

// 方法
const formatDate = (date) => {
  return new Date(date).toLocaleDateString('zh-CN', { 
    year: 'numeric', 
    month: 'long', 
    day: 'numeric' 
  })
}

const getTagType = (tag) => {
  const tagTypes = {
    '海洋保护': 'primary',
    '科研调查': 'warning',
    '环境教育': 'success',
    '珊瑚保护': 'danger',
    '海龟保护': 'info'
  }
  return tagTypes[tag] || ''
}

const handleJoinTeam = () => {
  team.value.isJoined = true
  team.value.memberCount++
  ElMessage.success('已成功加入团队！')
}

onMounted(() => {
  // 这里可以根据路由参数获取团队详情
  console.log('Team ID:', route.params.id)
})
</script>

<style scoped lang="scss">
.team-detail-page {
  min-height: 100vh;
  background-color: #f5f7fa;

  .team-header {
    background: linear-gradient(135deg, #409EFF 0%, #36D1DC 100%);
    padding: 60px 0;
    color: white;
    border-radius: 8px;


    .header-content {
      max-width: 1200px;
      margin: 0 auto;
      padding: 0 20px;
      display: grid;
      grid-template-columns: auto 1fr auto;
      gap: 40px;
      align-items: center;

      .team-avatar {
        width: 160px;
        height: 160px;
        border-radius: 50%;
        overflow: hidden;
        border: 6px solid rgba(255, 255, 255, 0.2);

        .el-image {
          width: 100%;
          height: 100%;
        }
      }

      .team-info {
        .team-title {
          display: flex;
          align-items: center;
          gap: 20px;
          margin-bottom: 16px;

          h1 {
            font-size: 2.5em;
            margin: 0;
          }

          .team-badges {
            display: flex;
            gap: 10px;
          }
        }

        .team-desc {
          font-size: 1.1em;
          opacity: 0.9;
          margin-bottom: 20px;
          max-width: 800px;
        }

        .team-meta {
          display: flex;
          gap: 24px;
          margin-bottom: 20px;

          .meta-item {
            display: flex;
            align-items: center;
            gap: 8px;
            opacity: 0.9;
          }
        }

        .team-tags {
          display: flex;
          gap: 10px;
          flex-wrap: wrap;
        }
      }

      .team-actions {
        display: flex;
        flex-direction: column;
        gap: 12px;
        

        .el-button {
          width: 100%; 
          margin-left: 0; /* 使按钮成为块级元素 */
        }
      }
    }
  }

  .team-stats-section {
    margin-top: -40px;
    margin-bottom: 40px;
    position: relative;
    z-index: 1;

    .stats-container {
      max-width: 1200px;
      margin: 0 auto;
      padding: 0 20px;
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 20px;

      .stat-card {
        background: white;
        padding: 24px;
        border-radius: 12px;
        text-align: center;
        box-shadow: 0 4px 20px rgba(0,0,0,0.05);

        .stat-value {
          font-size: 2em;
          font-weight: 600;
          color: #409EFF;
          margin-bottom: 8px;
        }

        .stat-label {
          color: #606266;
          font-size: 1em;
        }
      }
    }
  }

  .main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 60px;

    .team-tabs {
      background: white;
      padding: 30px;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0,0,0,0.05);

      .team-intro {
        h2 {
          font-size: 1.5em;
          color: #303133;
          margin: 30px 0 20px;

          &:first-child {
            margin-top: 0;
          }
        }

        p {
          color: #606266;
          line-height: 1.8;
          margin-bottom: 20px;
          white-space: pre-line;
        }

        ul {
          list-style: none;
          padding: 0;
          margin: 0;

          li {
            position: relative;
            padding-left: 24px;
            margin-bottom: 12px;
            color: #606266;
            line-height: 1.6;

            &::before {
              content: '';
              position: absolute;
              left: 0;
              top: 8px;
              width: 8px;
              height: 8px;
              border-radius: 50%;
              background: #409EFF;
            }
          }
        }
      }

      .members-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 30px;
        padding: 20px 0;

        .member-card {
          text-align: center;
          padding: 20px;
          background: #f5f7fa;
          border-radius: 12px;
          transition: transform 0.3s;

          &:hover {
            transform: translateY(-5px);
          }

          h3 {
            margin: 12px 0 4px;
            color: #303133;
          }

          .member-role {
            color: #409EFF;
            font-size: 0.9em;
            margin-bottom: 8px;
          }

          .member-stats {
            color: #909399;
            font-size: 0.9em;
          }
        }
      }

      .activities-list {
        .activity-item {
          display: flex;
          gap: 24px;
          padding: 20px;
          border-bottom: 1px solid #ebeef5;

          &:last-child {
            border-bottom: none;
          }

          .activity-image {
            width: 200px;
            height: 120px;
            border-radius: 8px;
          }

          .activity-content {
            flex: 1;

            h3 {
              font-size: 1.2em;
              color: #303133;
              margin: 0 0 12px;
            }

            p {
              color: #606266;
              margin-bottom: 16px;
              line-height: 1.6;
            }

            .activity-meta {
              display: flex;
              gap: 24px;
              margin-bottom: 16px;
              color: #909399;
              font-size: 0.9em;

              span {
                display: flex;
                align-items: center;
                gap: 6px;
              }
            }
          }
        }
      }
    }
  }
}

.image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f5f7fa;
  color: #909399;
}

@media (max-width: 1024px) {
  .team-detail-page {
    .team-header .header-content {
      grid-template-columns: 1fr;
      text-align: center;

      .team-avatar {
        margin: 0 auto;
      }

      .team-info {
        .team-title {
          justify-content: center;
        }

        .team-meta {
          justify-content: center;
        }

        .team-tags {
          justify-content: center;
        }
      }

      .team-actions {
        flex-direction: row;
        justify-content: center;
      }
    }

    .team-stats-section .stats-container {
      grid-template-columns: repeat(2, 1fr);
    }
  }
}

@media (max-width: 768px) {
  .team-detail-page {
    .team-header {
      padding: 40px 0;

      .header-content {
        .team-avatar {
          width: 120px;
          height: 120px;
        }

        .team-title h1 {
          font-size: 2em;
        }
      }
    }

    .main-content {
      .activities-list .activity-item {
        flex-direction: column;

        .activity-image {
          width: 100%;
          height: 200px;
        }
      }
    }
  }
}
</style> 